package leetcode.周赛.第274场;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2022/1/2 13:02
 * @description：https://leetcode-cn.com/problems/number-of-laser-beams-in-a-bank/
 */
public class 银行中的激光束数量 {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.numberOfBeams(new String[]{"000","111","000"}));
    }

    class Solution {
        public int numberOfBeams(String[] bank) {
            int pre = 0, cur;
            int ans = 0;
            for (String row : bank) {
                if (!row.contains("1")) continue;
                cur = 0;
                for (char c : row.toCharArray()) {
                    if (c == '1') cur++;
                }
                ans += pre * cur;
                pre = cur;
            }
            return ans;
        }
    }
}
